package com.shababeach.travel.controller;

import com.shababeach.travel.dto.LoginResponse;
import com.shababeach.travel.dto.Result;
import com.shababeach.travel.dto.WxLoginRequest;
import com.shababeach.travel.service.WxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/auth")
@CrossOrigin
public class AuthController {

    @Autowired
    private WxService wxService;

    /**
     * 微信登录接口
     *
     * @param wxLoginRequest 微信登录请求
     * @return 登录结果
     */
    @PostMapping("/wxlogin")
    public Result<LoginResponse> wxLogin(@RequestBody WxLoginRequest wxLoginRequest) {
        log.info("收到微信登录请求: {}", wxLoginRequest);
        try {
            LoginResponse loginResponse = wxService.wxLogin(wxLoginRequest);
            log.info("登录成功，返回: {}", loginResponse);
            return Result.success(loginResponse);
        } catch (Exception e) {
            log.error("登录失败", e);
            return Result.fail(e.getMessage());
        }
    }
} 